package com.controller;

import com.domain.Student;
import com.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Resource
    private StudentService service;

    @RequestMapping("/addStudent.do")
    public ModelAndView addStudent(Student student)
    {
        ModelAndView mv = new ModelAndView();
        String tips = "注册失败";
        int nums = service.addStudent(student);
        if (nums>0){
            tips="学生【"+student.getName()+"]注册成功";
        }
        mv.addObject("tips",tips);
        mv.setViewName("addresult");
        return mv;
    }
    @RequestMapping("/selectStudent.do")
    public ModelAndView loginUser(Student student, Model model) {
        Student student1 = service.findStudents(student);
        ModelAndView mv = new ModelAndView();
        if (student1 != null) {
            mv.addObject("msg",student1);
            mv.setViewName("result");
            return mv;
        }
        mv.setViewName("result");
        return mv;
    }

}
